package com.fit.pages.client;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.UserAccess;
import com.fit.dao.client.ClientDAO;
import com.fit.entities.Client;
import com.fit.pages.ErrorPage;

@AdminAccess
@UserAccess
public class InsertClient {

	@Property
	private Client client;

	@InjectPage
	private ErrorPage errorPage;

	@Inject
	private ClientDAO clientDAO;

	Object onSuccess() {
		errorPage.setMessage("");

		if (clientDAO.save(client)) {
			errorPage.setMessage("Client successfully added");
			return errorPage;
		} else {
			errorPage.setMessage("Client is null");
			return errorPage;
		}
	}

}
